package com.mux.util.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class DateUtils {
	
    public  static final String DATEFORMATSTR="yyyyMMdd";
	
	/**
	 * String 转为 Calendar
	 * @param date
	 * @param fmt
	 * @return
	 * @throws Exception
	 */
	public static Calendar stringDateToCalendar(String date,String fmt) throws Exception{
		SimpleDateFormat sdf= new SimpleDateFormat(fmt);
		Date calDate = sdf.parse(date);
		Calendar startCal = Calendar.getInstance();
		startCal.setTime(calDate);
		return startCal;
	}
	
	
	/**
	 * Calendar 转 String
	 * @param cal
	 * @param fmt
	 * @return
	 */
	public static String calendarToStringDate(Calendar cal,String fmt){
		SimpleDateFormat sdf = new SimpleDateFormat(fmt);
		return sdf.format(cal.getTime());
	}
	
	
	
	
	public static void main(String[] args) throws Exception {
		Calendar startCal = stringDateToCalendar("20161004",DATEFORMATSTR);
		Calendar endCal = stringDateToCalendar("20161018",DATEFORMATSTR);
		while(startCal.compareTo(endCal)<=0){
			System.out.println("i");
			startCal.add(Calendar.DATE,1);
		}
		
	}
}
